<template>
	<div class="app-container">
    <!-- 出库单一览 -->
    
		<!-- 高级查询 -->
		<el-tabs v-model="queryParams.status" type="card" @tab-click="handleQuery">
			<el-tab-pane name="created">
				<span slot="label"><i class="el-icon-bank-card" />新计划</span>
			</el-tab-pane>

			<!-- <el-tab-pane name="planed">
				<span slot="label"><i class="el-icon-bank-card" /> 已安排</span>
			</el-tab-pane>
			<el-tab-pane name="outed">
				<span slot="label"><i class="el-icon-bank-card" /> 待发货</span>
			</el-tab-pane>
			<el-tab-pane name="shipPlaned">
				<span slot="label"><i class="el-icon-bank-card" /> 已发货</span>
			</el-tab-pane> -->
		</el-tabs>
		<el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">

			<el-form-item label="仓库">

				<el-select v-model="queryParams.warehouseCode" filterable clearable placeholder="请选择">
					<el-option v-for="item in  options.warehouseCodes" :key="item.id" :label="item.warehouserName"
						:value="item.id">
					</el-option>

				</el-select>
			</el-form-item>


			<el-form-item label="选择商品车：" prop="materialNo">
				<el-input v-model="queryParams.materialNo" class="filter-item">
					<i slot="suffix" class="el-input__icon el-icon-search" @click="openMaterialSelector" />
				</el-input>
				<warehouse-customer-selector ref="warehouseCustomerSelector" :visible.sync="materialSelectorVisible"
					@selected="handleMaterialSelected" />
			</el-form-item>


			<el-form-item label="客户:">
				<el-select v-model="queryParams.customerNo" style="width: 100%" filterable clearable
					placeholder="请选择客户">
					<el-option v-for="option in options.customerOptions" :key="option.id" :label="option.customerName"
						:value="option.id" />
				</el-select>
			</el-form-item>

			<el-form-item label="入库批号:">
				<el-input v-model="queryParams.receivedLineId" size="small" placeholder="请输入" clearable
					@keyup.enter.native="handleQuery" />
			</el-form-item>


			<el-form-item>
				<el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
				<el-button icon="el-icon-download" type="warning" size="mini" @click="resetQuery">导出</el-button>
			</el-form-item>
		</el-form>

		<!-- 工具栏 -->
		<!-- <el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button v-hasPermission="['web:tbWmsMaterialDeliveryLine:insert']" type="primary" icon="el-icon-plus"
					size="mini" @click="handleAdd">新增</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button v-if="queryParams.status === `created`"
					v-hasPermission="['web:tbWmsMaterialDeliveryLine:update']" type="success" icon="el-icon-edit"
					size="mini" :disabled="isSingle" @click="handleEdit">修改</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button v-if="queryParams.status === `created`"
					v-hasPermission="['web:tbWmsMaterialDeliveryLine:delete']" type="danger" icon="el-icon-delete"
					size="mini" :disabled="isMultiple" @click="handleRemove">删除</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button v-hasPermission="['web:tbWmsMaterialDeliveryLine:export']" type="warning"
					icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button v-hasPermission="['web:tbWmsMaterialDeliveryLine:insert']" type="primary"
					icon="el-icon-download" size="mini" @click="handleGet">获取出库单</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button v-if="queryParams.status === `created`"
					v-hasPermission="['web:tbWmsMaterialDeliveryLine:insert']" type="info" icon="el-icon-upload2"
					size="mini" :disabled="isMultiple" @click="handleAssign">生成拣货计划</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button v-if="queryParams.status === `created`"
					v-hasPermission="['web:tbWmsMaterialDeliveryLine:insert']" type="info" icon="el-icon-upload2"
					size="mini" @click="handleAutoPick">自动拣货计划</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button v-if="queryParams.status === `created`"
					v-hasPermission="['web:tbWmsMaterialDeliveryLine:insert']" type="info" icon="el-icon-upload2"
					size="mini" @click="handlePublish">发布拣货任务</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button v-if="queryParams.status === `outed`"
					v-hasPermission="['web:tbWmsMaterialDeliveryLine:insert']" type="info" icon="el-icon-upload2"
					size="mini" :disabled="isMultiple" @click="handleFreight">发货</el-button>
			</el-col>
			<right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
		</el-row> -->

		<!-- 数据列表 -->
		<el-table v-loading="loading" :data="page.records" highlight-current-row
			@selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<!-- <el-table-column type="expand">
              <template slot-scope="props" style="padding: 20px 50px;">
                <el-table v-loading="loading" :data="props.row.receitems" highlight-current-row>
                  <el-table-column label="商品图片" align="center">
                    <template slot-scope="scope">
                      <a :title="scope.row.spuName" target="_blank" @click="toGoodsDetail(scope.row.spuId)">
                        <img :alt="scope.row.spuName" :src="attachUrl(scope.row.image)">
                      </a>
                    </template>
                  </el-table-column>
                  <el-table-column label="型号" align="center" prop="model" width="150px" />
                  <el-table-column label="商品名称" align="center" prop="materialName" width="150px" />
                  <el-table-column label="价格" align="center" prop="price" width="150px" />
                  <el-table-column label="数量" align="center" prop="qty" width="150px" />
                  <el-table-column label="小计" align="center">
                    <template slot-scope="scope">
                      ¥ {{ Number(scope.row.price * scope.row.qty).toFixed(2) }}
                    </template>
                  </el-table-column>
                </el-table>
              </template>
            </el-table-column> -->

			<el-table-column label="VIN号" align="center" prop="vinNo" width="150px"/>
			<el-table-column label="发车类型" align="center" prop="departureType" />
			<el-table-column label="工厂" align="center" prop="customerNo" />
			<el-table-column label="销售组织" align="center" prop="salesOrgNo" />
			<el-table-column label="分销渠道" align="center" prop="salesDistributor" />
			<el-table-column label="交货单号" align="center" prop="deliveryNo" />
			<el-table-column label="行项目" align="center" prop="projectLine" />
			<el-table-column label="转存单编号" align="center" prop="redepositReceipt" />
			<el-table-column label="发货库存地" align="center" prop="deliveryWarehouseCode" />
			<el-table-column label="仓储地点描述" align="center" prop="warehouseRemar" />
			<el-table-column label="收货库存地点描述" align="center" prop="receivingWarehouseRemar" />
			<el-table-column label="接收库存地点描述" align="center" prop="receiveWarehouseRemar" />
			<el-table-column label="数量" align="center" prop="quantity" />
			<el-table-column label="物流公司真实出库日期" align="center" prop="outboundDate" />
			<el-table-column label="物流公司真实出库目的地" align="center" prop="destination" />
			<el-table-column label="大小/尺寸" align="center" prop="goodsSize" />
			<el-table-column label="颜色" align="center" prop="goodsColour" />
			<el-table-column label="发动机型号" align="center" prop="engineModel" />
			<el-table-column label="发动机号" align="center" prop="engineNo" />
			<el-table-column label="公告号" align="center" prop="batchNo" />
			<el-table-column label="运输方式" align="center" prop="transportType" />
			<el-table-column label="装运编号" align="center" prop="shipmentNo" />
			<el-table-column label="过账日期" align="center" prop="transferItemsTime" />
			<el-table-column label="过账时间" align="center" prop="transferItemsDate" />
			<el-table-column label="要求发货时间" align="center" prop="requestDeliveryTime" />
			<el-table-column label="承运商" align="center" prop="carrierNo" />
			<el-table-column label="半挂车号" align="center" prop="trailerNo" />
			<el-table-column label="备注" align="center" prop="remark" />
			<el-table-column label="合格证传递指定" align="center" prop="appoint" />
			<el-table-column label="合格证说明" align="center" prop="illustrate" />
			<el-table-column label="销售配置串描述" align="center" prop="saleIllustrate" show-overflow-tooltip width="200" />
			<el-table-column label="需求日期" align="center" prop="requirementDate" />
			<el-table-column label="移动类型" align="center" prop="moveType" />
			<el-table-column label="新首次发车售达方" align="center" prop="firstConsignee" />
			<el-table-column label="首次发车售达方描述" align="center" prop="firstConsigneeName" />
			<el-table-column label="运输路线代码" align="center" prop="transportRoute" />
			<el-table-column label="运输路线描述" align="center" prop="transportRemark" />
			<el-table-column label="货物代码" align="center" prop="materialNo" />
			<el-table-column label="物料描述" align="center" prop="materialRemark" />
			<el-table-column label="订单颜色" align="center" prop="orderColor" />
			<el-table-column label="订单颜色描述" align="center" prop="orderColorRemark" />
			<el-table-column label="内编号" align="center" prop="internalNumber" />
			<el-table-column label="子品牌描述" align="center" prop="vehicleName" />
			<el-table-column label="产品线" align="center" prop="productLine" />
			<el-table-column label="产品线描述" align="center" prop="productLineRemark" />
			<el-table-column label="子产品线" align="center" prop="vehicleLine" />
			<el-table-column label="轴距" align="center" prop="wheelbase" />
			<el-table-column label="轴距描述" align="center" prop="wheelbaseRemark" />
			<el-table-column label="车身类型" align="center" prop="pilothouseType" />
			<el-table-column label="车身类型描述" align="center" prop="pilothouseTypeRemark" />
			<el-table-column label="吨位" align="center" prop="tonnage" />
			<el-table-column label="吨位描述" align="center" prop="tonnageRemark" />
			<el-table-column label="大区描述" align="center" prop="salesArea" />
			<el-table-column label="市场部描述" align="center" prop="marketDepartment" />
			<el-table-column label="客户编号" align="center" prop="consignee" />
			<el-table-column label="客户名称" align="center" prop="consigneeName" />
			<el-table-column label="省份描述" align="center" prop="collectionProvince" />
			<el-table-column label="经销商地址" align="center" prop="consigneeAddress" />
			<el-table-column label="经销商电话" align="center" prop="consigneePhoneNo" />
			<el-table-column label="销售订单" align="center" prop="salesOrder" />
			<el-table-column label="行项目" align="center" prop="lineItem" />
			<el-table-column label="终端价(含运费)" align="center" prop="terminalPrice" />
			<el-table-column label="预分配承运商" align="center" prop="preAllocationCarrier" />
			<el-table-column label="预分配承运商名称" align="center" prop="preAllocationCarrierName" />
			<el-table-column label="DMS订单号" align="center" prop="dmsOrderNo" />
			<el-table-column label="DMS点单库存地点" align="center" prop="dmsWarehouse" />


			<!-- <el-table-column label="存储库位" align="center" prop="locationNo" />
			<el-table-column label="出库单号" align="center" prop="orderNo" width="150px">
				<template slot-scope="scope">
					<a @click="toOrderDetail(scope.row.orderNo)">{{ scope.row.orderNo }}</a>
				</template>
			</el-table-column>
			<el-table-column label="物品名称" align="center" prop="materialName" width="150px" />
			<el-table-column label="物品号" align="center" prop="materialNo" width="150px" />
			<el-table-column label="业务单号" align="center" prop="batchNo" />
			<el-table-column label="状态" align="center" prop="status" />
			<el-table-column label="数量" align="center" prop="quantity" />
			<el-table-column label="客户名称" align="center" prop="consigneeAddress" />
			<el-table-column label="创建时间" align="center" prop="createTime" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
				</template>
			</el-table-column> -->
			<!-- <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button v-hasPermission="['web:tbWmsMaterialDeliveryLine:update']" size="mini" type="text"
						icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
					<el-button v-hasPermission="['web:tbWmsMaterialDeliveryLine:delete']" size="mini" type="text"
						icon="el-icon-delete" @click="handleRemove(scope.row)">删除</el-button>
				</template>
			</el-table-column> -->
		</el-table>

		<!-- 分页 -->
		<pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize"
			@pagination="handleQuery" />

		<!-- 添加/修改对话框 -->
		<el-dialog :title="freightDialog.title" :close-on-click-modal="false" :before-close="closeFreightDialog"
			:visible.sync="freightDialog.visible" width="35%">
			<el-form :model="freightDialogData" label-position="right" label-width="120px" class="dialog_form">

				<!-- <el-form-item label="运单类型">
					<el-select v-model="freightDialogData.orderTypeNo" clearable placeholder="请选择">
						<el-option v-for="item in  options.orderTypeNos" :key="item.key" :label="item.label"
							:value="item.key">
						</el-option>
					</el-select>
				</el-form-item> -->
				<el-form-item label="选择承运人">
					<el-select v-model="freightDialogData.carrier" clearable placeholder="请选择">
						<el-option v-for="item in  options.carriers" :key="item.id" :label="item.carrierName"
							:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="服务类型">
					<el-select v-model="freightDialogData.serviceType" clearable placeholder="请选择">
						<el-option v-for="item in  options.serviceTypes" :key="item.key" :label="item.label"
							:value="item.key">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="车辆类型">
					<el-select v-model="freightDialogData.vehicleModelNo" clearable placeholder="请选择">
						<el-option v-for="item in  options.vehicleModels" :key="item.id" :label="item.vehicleModelDesc"
							:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="是否中转">
					<el-select v-model="freightDialogData.transitWarehouseNo" clearable placeholder="请选择">
						<el-option v-for="item in  options.transitWarehouses" :key="item.id"
							:label="item.warehouserName" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="closeFreightDialog()">取消</el-button>
				<el-button type="primary" @click="confirmFreightDialog()">保存</el-button>
			</div>
		</el-dialog>
		<el-dialog :title="assignDialog.title" :close-on-click-modal="false" :before-close="closeAssignDialog"
			:visible.sync="assignDialog.visible" width="35%">
			<el-form :model="assignDialogData" label-position="right" label-width="120px" class="dialog_form">
				<el-form-item label="">
					<el-checkbox v-model="assignDialogData.needRepackYn"
						style="margin:0px 0px 25px 0px;">是否需要拆装</el-checkbox>


				</el-form-item>
				<el-form-item label="">
					<el-checkbox v-model="assignDialogData.needLiftYn"
						style="margin:0px 0px 25px 0px;">是否需要叉车</el-checkbox>

				</el-form-item>
				<el-form-item label="">
					<el-checkbox v-model="assignDialogData.needPalletYn"
						style="margin:0px 0px 25px 0px;">是否需要托盘</el-checkbox>

				</el-form-item>
				<el-table v-loading="loading" :data="employeePage.erecords" highlight-current-row>
					<el-table-column type="selection" width="55" align="center" />
					<el-table-column label="选择收货人员" align="center" prop="personName" />
					<el-table-column label="收货人员编号" align="center" prop="userId" />
					<el-table-column label="" align="center" prop="userType" />
					<el-table-column label="" align="center" prop="enrollDate" width="180">
						<template slot-scope="scope">
							<span>{{ parseTime(scope.row.enrollDate, '{y}-{m}-{d}') }}</span>
						</template>
					</el-table-column>
					<el-table-column label="" align="center" prop="currentJobLoad" />
					<el-table-column label="" align="center" prop="idCard" />
				</el-table>
				<pagination v-show="employeePage.total>0" :total="employeePage.total" :page.sync="employeePage.current"
					:limit.sync="employeePage.pageSize" />

				<el-table v-loading="loading" :data="employeeLiftPage.lrecords" highlight-current-row>
					<el-table-column type="selection" width="55" align="center" />
					<el-table-column label="选择叉车驾驶员" align="center" prop="personName" />
					<el-table-column label="叉车驾驶员编号" align="center" prop="userId" />
					<el-table-column label="" align="center" prop="userType" />
					<el-table-column label="" align="center" prop="enrollDate" width="180">
						<template slot-scope="scope">
							<span>{{ parseTime(scope.row.enrollDate, '{y}-{m}-{d}') }}</span>
						</template>
					</el-table-column>
					<el-table-column label="" align="center" prop="currentJobLoad" />
					<el-table-column label="" align="center" prop="idCard" />
				</el-table>
				<pagination v-show="employeeLiftPage.total>0" :total="employeeLiftPage.total"
					:page.sync="employeeLiftPage.current" :limit.sync="employeeLiftPage.pageSize" />
				<!--  <el-form-item label="选择接货人员：">
           <el-select v-model="assignDialogData.jobPerson" placeholder="请选择" clearable size="mini">
             <el-option v-for="option in  options.jobPersons" :key="option.key" :label="option.label" :value="option.key" />
           </el-select>
         </el-form-item>
         <el-form-item label="选择叉车：">
           <el-select v-model="assignDialogData.liftPerson" placeholder="请选择" clearable size="mini">
             <el-option v-for="option in  options.liftPersons" :key="option.key" :label="option.label" :value="option.key" />
           </el-select>
         </el-form-item> -->
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="closeAssigDialog()">取消</el-button>
				<el-button type="primary" @click="confirmAssigDialog()">保存</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import TbWmsMaterialDeliveryLineApi from '@/api/web/TbWmsMaterialDeliveryLineApi'
	import TbWmsMaterialDeliveryApi from '@/api/web/TbWmsMaterialDeliveryApi'
	import HrEmployeeManageApi from '@/api/basic/HrEmployeeManageApi'
	import TWmsDeliveryPickupPlanApi from '@/api/web/TWmsDeliveryPickupPlanApi'
	import CustomerApi from '@/api/basic/CustomerApi';
	import CarrierApi from '@/api/basic/CarrierApi';
	import TViVehicleModelApi from '@/api/tms/TViVehicleModelApi'

	import WarehouseCustomerSelector from '@/views/pms/tWhWarehouseCustomerMaterial/WarehouseCustomerSelector'
	import WarehouseApi from '@/api/basic/WarehouseApi'
	const defaultTbWmsMaterialDeliveryLineFormData = {
		orderNo: null,
		lineNo: null,
		materialNo: null,
		planQuantity: null,
		deliveryQuantity: null,
		status: '0',
		truckFee: null,
		freightQuantity: null,
		version: null,
		quantity: null,
		measUnitNo: null,
		customerNo: null,
		deliveryId: null,
		freightorderLineSeqId: null,
		locationNo: null,
		batchNo: null,
		palletQty: null,
	}
	export default {
		name: 'TbWmsMaterialDeliveryLineList',
		components: {

			WarehouseCustomerSelector

		},
		data() {
			return {
				options: {
					sysYnTypeOptions: this.$constant.sysYnTypeOptions,
					orderTypeNos: this.$constant.orderTypeOptions,
					serviceTypes: this.$constant.serviceTypeOptions,
					customerOptions: [],
					transitWarehouses: [],
					vehicleModels: [],
					warehouseCodes: [],
					carriers: []
				},
				queryParams: {
					orderNo: null,
					lineNo: null,
					materialNo: null,
					planQuantity: null,
					deliveryQuantity: null,
					status: 'created',
					remark: null,
					truckFee: null,
					freightQuantity: null,
					version: null,
					quantity: null,
					measUnitNo: null,
					customerNo: null,
					deliveryId: null,
					freightorderLineSeqId: null,
					locationNo: null,
					batchNo: null,
					palletQty: null,
					createTime: null,
					isValid: this.$constant.Y
				},
				page: {
					current: 1,
					pageSize: 10,
					total: 0,
					records: []
				},
				employeePage: {
					current: 1,
					pageSize: 10,
					total: 0,
					erecords: []
				},
				employeeLiftPage: {
					current: 1,
					pageSize: 10,
					total: 0,
					lrecords: []
				},
				tbWmsMaterialDeliveryLineFormDialog: {
					title: '',
					visible: false
				},
				tbWmsMaterialDeliveryLineFormData: Object.assign({}, defaultTbWmsMaterialDeliveryLineFormData),
				tbWmsMaterialDeliveryLineFormRules: {
					orderNo: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					lineNo: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					materialNo: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					planQuantity: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					deliveryQuantity: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					status: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					version: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
				},
				freightDialog: {
					title: '发货',
					visible: false
				},
				freightDialogData: {
					orderTypeNo: null,
					vehicleModelNo: null,
					carrier: null,
					transitWarehouseNo: null,
					serviceType: null,
					ids: []
				},
				assignDialog: {
					title: '分配任务',
					visible: false
				},
				assignDialogData: {
					needRepackYn: null,
					needLiftYn: null,
					liftEmployees: [],
					pickEmployees: [],
					needPalletYn: null,
					ids: []
				},
				loading: true,
				searchVisible: true,
				multipleSelection: [],
				materialSelectorVisible: false,
				isSingle: true,
				isMultiple: true
			}
		},
		created() {
			//	this.queryParams.createTime = this.$route.query.createTime
			this.handleQuery()

			this.loadOptions()
		},
		methods: {
			loadOptions() {

				let that = this;
				TViVehicleModelApi.list().then(res => {
					that.options.vehicleModels = res.data

				})

				WarehouseApi.list().then(response => {
					that.options.warehouseCodes = response.data
				})

				/*  queryParams.userType ='recept'
				  HrEmployeeManageApi.list(queryParams).then(response => {
				    that.options.jobPersons = response.data
				  }) */
				CustomerApi.list().then(res => {
					that.options.customerOptions = res.data

				})
				CarrierApi.list().then(res => {
					that.options.carriers = res
				})
				const params = {
					warehouseType: "transit"
				}
				WarehouseApi.list(params).then(res => {
					that.options.transitWarehouses = res.data
				})

				/* queryParams.userType ='lift'
				       HrEmployeeManageApi.list(queryParams).then(response => {
				         this.options.liftPersons = response.data
				       }) */

			},
			handleAdd() {
				this.openTbWmsMaterialDeliveryLineFormDialog()
			},
			handleRemove(row) {
				const ids = row.id || this.multipleSelection.map(item => item.id)
				this.$confirm('是否确认删除数据?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(function() {
					return TbWmsMaterialDeliveryLineApi.remove(ids)
				}).then(() => {
					this.handleQuery()
					this.$message.success('删除成功')
				})
			},

			handleEdit(row) {
				const id = row.id || this.multipleSelection.map(item => item.id)[0]
				this.openTbWmsMaterialDeliveryLineFormDialog(id)
			},
			handleAutoPick() {
				TWmsDeliveryPickupPlanApi.pickPlan().then(response => {
					this.$message.success('上架计划生成成功')
					this.handleQuery()
				})
			},
			openMaterialSelector() {
				this.$refs.warehouseCustomerSelector.loadData()
				this.materialSelectorVisible = true
			},
			handleMaterialSelected(obj) {
				this.queryParams.materialNo = obj.id
			},
			handlePublish() {
				TWmsDeliveryPickupPlanApi.handlePublish().then(response => {
					this.$message.success('上架计划生成成功')
					this.handleQuery()
				})
			},
			closeFreightDialog() {
				this.freightDialog = {
					title: ' 安排',
					visible: false
				}
				this.freightDialogData = {
					ids: null,
					serviceType: null,
					carrier: null,
					transitWarehouseNo: null,
					vehicleModel: null,
					orderType: null

				}
				this.handleQuery()
			},

			handleFreight(row) {
				const ids = row.id || this.multipleSelection.map(item => item.id)
				this.freightDialog.visible = true
				this.freightDialogData.ids = ids
			},
			confirmFreightDialog() {


				const ids = this.multipleSelection.map(item => item.id)
				TWmsDeliveryPickupPlanApi.handleFreight(this.freightDialogData, ids).then(response => {
					this.$message.success('发货成功')
				})
				this.freightDialog.visible = false


				this.closeFreightDialog()

				this.handleQuery()
			},
			handleAssign(row) {
				const ids = row.id || this.multipleSelection.map(item => item.id)
				this.assignDialog.visible = true
				this.assignDialogData.ids = ids
			},
			confirmAssigDialog() {

				this.assignDialogData.liftEmployees = this.lemployeeSelecMultipleSelection.map(item => item.id)
				this.assignDialogData.pickEmployees = this.employeeSelecMultipleSelection.map(item => item.id)

				console.log(params)
				const ids = this.multipleSelection.map(item => item.id)
				TWmsDeliveryPickupPlanApi.pickPlanBySelectItem(this.assignDialogData, ids).then(response => {
					this.$message.success('上架计划生成成功')
				})
				this.assignDialog.visible = false


				this.closeAssignDialog()

				this.handleQuery()
			},
			closeAssignDialog() {
				this.assignDialog = {
					title: ' 安排',
					visible: false
				}
				this.assignDialogData = {
					ids: null,
					orderTypeNo: null,
					vehicleModelNo: null,
					serviceType: null
				}
				this.handleQuery()
			},
			handleInitQuery() {
				this.loading = true
				this.queryParams.status = "created"
				this.queryParams.deliveryType = "vehicle"
				TbWmsMaterialDeliveryLineApi.page(this.queryParams, this.page).then(response => {
					this.page.records = response.data.records
					this.page.total = response.data.total
					this.loading = false
				}, () => {
					this.loading = false
				})
			},
			handleQuery() {
				this.loading = true
				this.queryParams.deliveryType = "vehicle"
				TbWmsMaterialDeliveryLineApi.page1(this.queryParams, this.page).then(response => {
					this.page.records = response.data.records
					this.page.total = response.data.total
					this.loading = false
				}, () => {
					this.loading = false
				})
			},
			handleExport() {
				this.$confirm('是否确认导出数据?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(function() {
					return TbWmsMaterialDeliveryLineApi.exportData(this.queryParams)
				}).then(response => {
					this.$common.download(response.msg)
				})
			},
			openTbWmsMaterialDeliveryLineFormDialog(id) {
				this.resetTbWmsMaterialDeliveryLineFormDialog()
				this.tbWmsMaterialDeliveryLineFormDialog.visible = true
				if (id) {
					this.tbWmsMaterialDeliveryLineFormDialog.title = '出库明细-修改'
					TbWmsMaterialDeliveryLineApi.get(id).then(response => {
						this.tbWmsMaterialDeliveryLineFormData = {
							...this.tbWmsMaterialDeliveryLineFormData,
							...response.data
						}
					})
				} else {
					this.tbWmsMaterialDeliveryLineFormDialog.title = '出库明细-添加'
				}
			},
			confirmTbWmsMaterialDeliveryLineFormDialog() {
				this.$refs['tbWmsMaterialDeliveryLineForm'].validate(valid => {
					if (valid) {
						if (this.tbWmsMaterialDeliveryLineFormData.id) {
							TbWmsMaterialDeliveryLineApi.edit(this.tbWmsMaterialDeliveryLineFormData).then(
								response => {
									this.$message.success('修改成功')
									this.tbWmsMaterialDeliveryLineFormDialog.visible = false
									this.handleQuery()
								})
						} else {
							TbWmsMaterialDeliveryLineApi.add(this.tbWmsMaterialDeliveryLineFormData).then(
								response => {
									this.$message.success('添加成功')
									this.tbWmsMaterialDeliveryLineFormDialog.visible = false
									this.handleQuery()
								})
						}
					}
				})
			},
			resetTbWmsMaterialDeliveryLineFormDialog() {
				this.tbWmsMaterialDeliveryLineFormDialog = {
					title: '',
					visible: false
				}
				this.tbWmsMaterialDeliveryLineFormData = Object.assign({}, defaultTbWmsMaterialDeliveryLineFormData)
				this.resetForm('tbWmsMaterialDeliveryLineForm')
			},

			handleGet() {
				this.$alert("生成出库计划成功");
				this.handleQuery()
			},
			handleSelectionChange(selection) {
				this.multipleSelection = selection
				this.isSingle = selection.length !== 1
				this.isMultiple = !selection.length
			},
			resetQuery() {
				this.page.current = 1
				this.resetForm('queryForm')
				this.handleQuery()
			}
		}
	}
</script>
